/*
 * @Author: 矫建武 1452239416@qq.com
 * @Date: 2024-12-12 16:38:27
 * @LastEditTime: 2025-02-17 10:10:01
 * @FilePath: \toolDb\app.js
 * @Description: 
 * 
 * @file: https://github.com/OBKoro1/koro1FileHeader/wiki/%E5%AE%89%E8%A3%85%E5%92%8C%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B
 */

const express = require("express")
const path = require("path")
const cookieParser = require("cookie-parser")
const logger = require("morgan")
const cors = require('cors')
const { sends, checkToken, errorHandling } = require("./utils/middleware")

const usersRouter = require("./routes/users")
const registerRouter = require("./routes/register")
const tool = require("./routes/tool")
const upload = require("./routes/upload")
const uiComponents = require("./routes/uiComponents")
const userInfo = require("./routes/userInfo")

const app = express()
const http = require("http")
const server = http.createServer(app)
app.use(logger("dev"))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(cors())
app.use(express.static(path.join(__dirname, "public")))

app.use(sends)
app.use(checkToken)
app.use("/api", usersRouter)//用户
app.use("/api", registerRouter)//登录用
app.use("/api", tool)
app.use("/api", upload)
app.use("/api", uiComponents)
app.use("/api", userInfo)
app.use(errorHandling)//登录用
server.listen("1024")
